package com.flute.tools.sql;

public class OrderBySQL implements ISQL {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1690455484006921669L;
	private FieldsSQL fields;
	private FieldsSQL desFields;

	public OrderBySQL() {
		this.fields = new FieldsSQL();
		this.desFields = new FieldsSQL();
	}

	public void addField(String field) {
		this.fields.addField(field);
	}

	public void addDescField(String field) {
		this.desFields.addField(field);
	}

	@Override
	public String getSQLString() {
		if (fields.size() == 0 && desFields.size() == 0) {
			return "";
		} else {
			String field = fields.getSQLString();
			if (fields.size() > 0 && desFields.size() > 0) {
				field = field + ", " + desFields.getSQLString();
			} else if (fields.size() == 0 && desFields.size() > 0) {
				field = desFields.getSQLString();
			}

			return " order by " + field + SQLUtils.BLANK;
		}
	}

}
